package com.nuoniu.sibanyun.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.nuoniu.sibanyun.entity.SysRoleDataScope;
import com.nuoniu.sibanyun.entity.bo.SysUserDataScopeBo;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * <p>
 * 角色数据权限表 Mapper 接口
 * </p>
 *
 * @author baiqiang
 * @since 2020-05-25
 */
@Mapper
@Component
public interface SysRoleDataScopeMapper extends BaseMapper<SysRoleDataScope> {

    /**
     * 获取角色机构数据权限
     * @author 小啊刚
     * @date 2020/5/30
     */
    @Select("select ctrl_data from sys_role_data_scope where role_id = #{roleId} and ctrl_type = 'office'")
    List<String> checkOfficeList(Long roleId, String type);

    /**
     * 获取角色用户数据权限
     * @author 小啊刚
     * @date 2020/6/3
     */
    @Select("select concat(ctrl_data, '_user') from sys_role_data_scope where role_id = #{roleId} and ctrl_type = 'user'")
    List<String> checkUserList(Long roleId, String type);

    @Select("SELECT ds.role_id as roleId,ds.ctrl_type as ctrlType,GROUP_CONCAT(ds.ctrl_data) as ctrlDatas FROM sys_role_data_scope ds WHERE ds.role_id in(#{roleIds}) GROUP BY ds.role_id,ds.ctrl_type")
    List<SysUserDataScopeBo> getSysUserDataScopeBoByRoleIds(String roleIds);
}
